<?php
	MYDCONN();
	
	if (isset($_GET['at'])) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_contractos
					SET 
						Description = '{$_POST['Desc']}',
						Client = '{$_POST['Client']}',
						Status = {$_POST['Status']},
						NIB = '{$_POST['NIB']}'
					WHERE
						Ref = {$_POST['ccptID']}");
	$GET[1]['ref'] = $_GET['at'];
	} elseif (isset($_POST['RemContract'])) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_providers
			SET Status = 5
			WHERE Ref = {$_POST['ReProvider']}");
	} else {
	if (!isset($_POST['Desc']) || $_POST['Desc'] == '') {
		$Msg_ERROR = 'Preencha o campo Designa��o';
	} else {
	$GLOBALS['MYD']->db_query("INSERT INTO ccenter_contractos
			(RefProvider, PayPeriod, PayMode, Description, Status, Type, Client, CODE, NIB)
			VALUES
			({$_POST['Provider']},0,0,'{$_POST['Desc']}',2,1,'{$_POST['Client']}',{$_POST['CODE']}, '{$_POST['NIB']}')");
	
	$GET = $GLOBALS['MYD']->db_array("SELECT ref FROM ccenter_contractos
			WHERE RefProvider = {$_POST['Provider']}
			ORDER BY Ref DESC LIMIT 0,1");
	}
	}
	if (isset($_POST['RemProviderCode'])) {
	$GLOBALS['MYD']->db_query("UPDATE ccenter_providerscodes
			SET Status = 5
			WHERE Ref = {$_POST['RefProvider']}");
			}
	if (isset($Msg_ERROR)) {
		echo '<div class="Error">'.$Msg_ERROR.'</div>';
	} else {
		echo '<div class="Confirm">Concluido.</div>
		<script charset="utf-8" type="text/javascript">
		document.edtCdcInvoice.action=\'Modules/CentrodeCustos/Lib/sel_contract.php?id='.$GET[1]['ref'].'\';
		subform(\'edtCdcInvoice\',\'ContractDiv\');
		Ext.getCmp(\'winprop\').close();</script>';
	}
?>